/*
  将下面异步代码使用 Promise 的方法改进
  尽量用看上去像同步代码的方式
  setTimeout(function () {
    var a = 'hello'
    setTimeout(function () {
      var b = 'lagou'
      setTimeout(function () {
        var c = 'I ♥ U'
        console.log(a + b +c)
      }, 10)
    }, 10)
  }, 10)
*/

function aaa() {
  setTimeout(function () {
    var a = 'hello'
    setTimeout(function () {
      var b = 'lagou'
      setTimeout(function () {
        var c = 'I ♥ U'
        console.log(a + b +c)
      }, 10)
    }, 10)
  }, 10)
}

async function bbb() {
  await sleep(10);
  let a = 'hello';
  await sleep(10);
  let b = 'lagou';
  await sleep(10);
  let c = 'I ♥ U';
  console.log(a + b + c);
}

function sleep(time) {
  return new Promise((resolve) => {
    setTimeout(() => {
      console.log('sleeping');
      resolve();
    }, time);
  })
}

bbb();
